﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using BHXH_NT.Properties;
namespace BHXH_NT
{
    public partial class MDIMain : Form
    {
       

        public MDIMain()
        {
            InitializeComponent();
        }

        private void ShowNewForm(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            Form childForm = GetForm("frmChangeID");
            if (childForm == null)
            {
                childForm = new frmChangeID();
                childForm.MdiParent = this;
                childForm.Show();
                childForm.WindowState = FormWindowState.Maximized;
            }
            else
            {
                childForm.Activate();
            }
            Cursor.Current = Cursors.Default;

            
        }
        

       

        private void SaveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            openToolStripButton_Click(null, null);
            
        }

        private void ExitToolsStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void CutToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void CopyToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void PasteToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void ToolBarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            toolStrip.Visible = toolBarToolStripMenuItem.Checked;
        }

        private void StatusBarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            statusStrip.Visible = statusBarToolStripMenuItem.Checked;
        }

        private void CascadeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.Cascade);
        }

        private void TileVerticalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileVertical);
        }

        private void TileHorizontalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileHorizontal);
        }

        private void ArrangeIconsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.ArrangeIcons);
        }

        private void CloseAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (Form childForm in MdiChildren)
            {
                childForm.Close();
            }
        }

        private void MDIMain_Load(object sender, EventArgs e)
        {
           
            FrmLogin childForm;
            childForm = new FrmLogin();
            childForm.ShowDialog();
            
            if (childForm.flagExit == false){this.Close();}
            if (childForm.flagUser == true)
            {
                tsbHieuChinh.Enabled = false;
                HSCNToolStripButton.Enabled = false;
                TaoTheToolStripButton.Enabled = false;
                openToolStripButton.Enabled = false;
                saveToolStripButton.Enabled = false;
                toolStripButton1.Enabled = false;
                IntoroitoolStripButton.Enabled = false;
                printToolStripButton.Enabled = false;
                tsbAcount.Enabled = true;
            }
            else
            {
                tsbHieuChinh.Enabled = true;
                HSCNToolStripButton.Enabled = true;
                TaoTheToolStripButton.Enabled = true;
                openToolStripButton.Enabled = true;
                saveToolStripButton.Enabled = true;
                toolStripButton1.Enabled = true;
                IntoroitoolStripButton.Enabled = true;
                printToolStripButton.Enabled = true;
                tsbAcount.Enabled = false;

            }

            BHXH_NT.ModuleBHXH.strYear = BHXH_NT.ModuleBHXH.GetYear();
            BHXH_NT.ModuleBHXH.strMonths = BHXH_NT.ModuleBHXH.GetMonth();
            BHXH_NT.ModuleBHXH.strDate = BHXH_NT.ModuleBHXH.GetDate();
            if (Convert.ToInt32(BHXH_NT.ModuleBHXH.strMonths) > 201412) { this.Close(); }

        }
        
        private void saveToolStripButton_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            Form childForm = GetForm("BHYTTREEM");
            if (childForm == null)
            {
                childForm = new BHYTTREEM();
                childForm.MdiParent = this;
                childForm.Show();
                childForm.WindowState = FormWindowState.Maximized;
            }
            else
            {
                childForm.Activate();
            }
            Cursor.Current = Cursors.Default;
        }

        private void printToolStripButton_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            Form childForm = GetForm("frmBCCT");
            if (childForm == null)
            {
                Cursor.Current = Cursors.Default;
                childForm = new frmBCCT();
                childForm.MdiParent = this;
                childForm.StartPosition = FormStartPosition.CenterParent;
                childForm.WindowState = FormWindowState.Normal;
                childForm.Show();
            }
            else
            {
                childForm.Activate();
            }
           
          
            
        }
        private void printPreviewToolStripButton_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            Form childForm = GetForm("frmHSCN");
            if (childForm == null)
            {
                childForm = new frmHSCN();
                childForm.MdiParent = this;
                childForm.Show();
                childForm.WindowState = FormWindowState.Maximized;
            }
            else
            {
                childForm.Activate();
            }
            Cursor.Current = Cursors.Default;
        }

       
        private Form GetForm(String FormName)
        {
            foreach (Form f in this.FindForm().MdiChildren)
            {
                if (f.Name == FormName)
                    return f;
            }
            return null;
        }

        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TaoTheToolStripButton_Click_1(null, null);
        }

        private void TaoTheToolStripButton_Click_1(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            Form childForm = GetForm("frmCreateBHYT");
            if (childForm == null)
            {
                childForm = new frmCreateBHYT();
                childForm.MdiParent = this;
                childForm.Show();
                childForm.WindowState = FormWindowState.Maximized;
            }
            else
            {
                childForm.Activate();
            }
            Cursor.Current = Cursors.Default;
        }

        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            saveToolStripButton_Click(null,null);
        }

        private void selectAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            printToolStripButton_Click(null, null);
        }

        private void openToolStripButton_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            Form childForm = GetForm("frmBHYT");
            if (childForm == null)
            {
                childForm = new frmBHYT();
                childForm.MdiParent = this;
                childForm.Show();
                childForm.WindowState = FormWindowState.Maximized;
            }
            else
            {
                childForm.Activate();
            }
            Cursor.Current = Cursors.Default;
        }

        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            printPreviewToolStripButton_Click(null, null);
        }

        private void MDIMain_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F12 && e.Shift == true)
            {
                Cursor.Current = Cursors.WaitCursor;
                Form childForm = GetForm("frmSetting");
                if (childForm == null)
                {
                    childForm = new frmSetting();
                    childForm.MdiParent = this;
                    childForm.Show();
                }
                else
                {
                    childForm.Activate();
                }
                Cursor.Current = Cursors.Default;
            }
              
        }

        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            Form childForm = GetForm("frmAbout");
            if (childForm == null)
            {
                childForm = new frmAbout();
                //childForm.MdiParent = this;
                childForm.ShowDialog();
               
            }
            else
            {
                childForm.Activate();
            }
            Cursor.Current = Cursors.Default;
        }

        private void IntoroitoolStripButton_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            Form childForm = GetForm("FrmInToRoi");
            if (childForm == null)
            {
                childForm = new FrmInToRoi();
                childForm.MdiParent = this;
                childForm.Show();
                childForm.WindowState = FormWindowState.Maximized;
            }
            else
            {
                childForm.Activate();
            }
            Cursor.Current = Cursors.Default;
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            Form childForm = GetForm("FrmInToBia");
            if (childForm == null)
            {
                childForm = new FrmInToBia();
                childForm.MdiParent = this;
                childForm.Show();
                childForm.WindowState = FormWindowState.Maximized;
            }
            else
            {
                childForm.Activate();
            }
            Cursor.Current = Cursors.Default;
        }

        private void tsbAcount_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            Form childForm = GetForm("FrmAccount");
            if (childForm == null)
            {
                childForm = new FrmAccount();
                childForm.MdiParent = this;
                childForm.Show();
                childForm.WindowState = FormWindowState.Maximized;
            }
            else
            {
                childForm.Activate();
            }
            Cursor.Current = Cursors.Default;
        }

        private void tsbLogin_Click(object sender, EventArgs e)
        {
            MDIMain_Load(null, null);
        }

        private void tsMaCV_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            Form childForm = GetForm("frmCheckMaCV");
            if (childForm == null)
            {
                childForm = new frmCheckMaCV();
                childForm.MdiParent = this;
                childForm.Show();
                childForm.WindowState = FormWindowState.Maximized;
            }
            else
            {
                childForm.Activate();
            }
            Cursor.Current = Cursors.Default;
        }
             
    }
}
